<template>
  <!-- vue实例外创建 -->
  <div>
    <van-nav-bar title="我的发布" left-arrow @click-left="$router.back()" />

    <div
      v-for="(item, index) in ismet"
      :key="item._id"
      class="box"
      @click="$router.push({ name: 'detail', query: { article_id: item._id } })"
    >
      <van-swipe-cell>
        <div>{{ item.title }}</div>
        <div>{{ item.author }}</div>
        <img :src="item.imageSrc" alt="" />

        <template #right>
          <van-button
            square
            text="删除"
            type="danger"
            class="delete-button"
            @click="getdelet(item._id, index)"
          />
        </template>
      </van-swipe-cell>
    </div>
  </div>
</template>
<!-- 调用   <mycom></mycom> -->
<script>
import { SwipeCell } from "vant";

export default {
  name: "eatle",
  data() {
    return {
      ismet: [],
    };
  },
  components: {
    [SwipeCell.name]: SwipeCell,
  },
  created() {
    this.getmyhead();
  },
  methods: {
    getmyhead() {
      let uid = localStorage.getItem("tt-uid");
      //   console.log();
      this.$http({
        url: "/api/get_user_article_list",
        method: "POST",
        //传参
        data: {
          uid,
        },
      }).then((res) => {
        console.log(res.data);
        this.ismet = res.data;
      });
    },
    getdelet(_id, index) {
      let uid = localStorage.getItem("tt-uid");

      console.log(_id, index);
      this.$http({
        url: "/api/del_user_article",
        method: "POST",
        //传参
        data: {
          uid,
          _id,
        },
      }).then((res) => {
        console.log(res.data);
        if (res.code == 0) {
          this.ismet.splice(index, 1);
          this.$toast(res.msg);
        } else {
          this.$toast(
            res.msg || "删除失败                                    "
          );
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
img {
  height: 240px;
  width: 300px;
}
.delete-button {
  height: 100%;
}
</style>>


